#nginx官方包
FROM nginx:1.23.4-alpine
#各模块版本变量参数
ARG NGINX_VERSION=1.23.4
# https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz
ARG NGX_WEBDAV_VERSION=3.0.0
#换国内源
RUN cat /etc/apk/repositories | sed -e "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/" | tee /etc/apk/repositories
COPY packages/*.tar.gz /usr/src

#编译环境
RUN \
    apk update && apk add --no-cache --virtual \
        .build-deps gcc libc-dev make openssl-dev pcre2-dev zlib-dev linux-headers libxslt-dev gd-dev geoip-dev perl-dev libedit-dev mercurial bash alpine-sdk findutils && \
    cd /usr/src && \
#     curl -L "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" -o nginx.tar.gz && \
#     curl -L "https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v${NGX_WEBDAV_VERSION}.tar.gz" -o webdav.tar.gz && \
    set -ex && \
    tar -zxvf webdav.tar.gz && \
    tar -zxC /usr/src -f nginx.tar.gz && \
    cd /usr/src/nginx-$NGINX_VERSION && \
    CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p') \
    CONFARGS=${CONFARGS/-Os -fomit-frame-pointer -g/-Os} && \
    echo $CONFARGS && \
    ./configure --with-compat $CONFARGS --with-http_dav_module --add-module=../nginx-dav-ext-module-${NGX_WEBDAV_VERSION}/ && \
    make -j4 && make install && \
    apk del .build-deps && \
    rm -rf /tmp/* && rm -rf /var/cache/apk/* && rm -rf /usr/src/ && mkdir data

# docker build -t nginx_webdav:latest .
# docker run --rm --name dav nginx_webdav nginx -V
# docker tag nginx_webdav:latest cffycls/dav:latest
